package net.zjitc.jdbc.book;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;

/**
 * @Author admin
 * @Date 2019/4/26 8:46
 */
public class Test {
    static BookDaoDb dao=new BookDaoDb();
    static  Scanner scanner =new Scanner(System.in);
    static   Scanner scannerDouble=new Scanner(System.in);
    static  Scanner scannerInt =new Scanner(System.in);
    public static void main(String[] args) {
    while (true){
        System.out.println("欢迎进入图书管理系统：");
        System.out.println("1---保存图书");
        System.out.println("2---查询图书");
        System.out.println("3---更新图书");
        System.out.println("4---删除图书");
        System.out.println("5---退出");
        int choose =scannerInt.nextInt();
        switch (choose){
            case 1:
                InsertUi();
                break;
            case 2:
                selectUi();
                break;
            case 3:
                updateUi();
                break;
            case 4:
                delectUi();
                break;
            case 5:
                System.out.println("欢迎下次光临！");
                System.exit(0);
        }
        
    }
       
       
    }

    private static void delectUi() {
    }

    private static void updateUi() {
    }

    private  static void InsertUi(){
       System.out.println("请输入图书名称：");
       String name=scanner.nextLine();
       System.out.println("请输入出版社");
       String press=scanner.nextLine();
       System.out.println("请输入作者：");
       String author =scanner.nextLine();
       System.out.println("请输入图书价格");
       double price=  scannerDouble.nextDouble();
       Book book=new Book(name,press,author,price);
       int c=dao.insert(book);
       if (c>0){
           System.out.println("添加成功");
       }else{
           System.out.println("添加失败");
       }
   } 
    private  static void selectUi(){
        System.out.println("所有图书信息如下");
        System.out.println("编号\t出版社\t作者\t价格");
       // dao.select;
        ArrayList<Book> arrayList=dao.selectall();
        Iterator<Book> iterator=arrayList.iterator();
        while (iterator.hasNext()){
            Book book=iterator.next();
            System.out.println(book.getId()+"\t"+book.getName()+"\t"+book.getPress()
                              +"\t"+book.getAuthor()+"\t"+book.getPrice());
        }
    }
  
}
